<script>
// 引用swiper插件js
//import Swiper from 'swiper';
import { Swiper, SwiperSlide } from 'swiper/vue';
// Import Swiper styles
import 'swiper/css';
import 'swiper/css/pagination';
import 'swiper/css/navigation';
// import required modules  官网DEMO演示  https://swiperjs.com/demos
import { Autoplay, Pagination, Navigation } from 'swiper/modules';

export default {
  components: {
    Swiper,
    SwiperSlide,
  },
  props: {
    goodsList: {
      type: Array,
      default: () => []
    }
  },
  setup() {
    return {
      modules: [Autoplay, Pagination, Navigation],
    };
  },
};
</script>

<template>
  <div class="swiper-group">
    
    <!--
      // 默认左右切换按钮
      :navigation="true"
    -->
    
    <swiper
      :autoplay=" {
        delay: 3000,
        disableOnInteraction: false,
      }"
      :slidesPerView="4"
      :spaceBetween="20"
      :loop="true"
      :pagination="{
        clickable: true,
      }"
      :navigation="{
        nextEl: `.swiper-button-next`,
        prevEl: `.swiper-button-prev`,
      }"
      :modules="modules"
      :breakpoints="{
        '640': {
          slidesPerView: 2,
          spaceBetween: 20,
        },
        '768': {
          slidesPerView: 3,
          spaceBetween: 20,
        },
        '1024': {
          slidesPerView: 4,
          spaceBetween: 20,
        },
      }"
      class="mySwiper"
    >
      <swiper-slide v-for="(goods,index) in goodsList" :key="index">
        <RouterLink class="goods-item" :to="`/detail/${goods.id}`">
          <div class="pic"><img v-img-lazy="goods.picture" /></div>
          <div class="info-desc">
            <p class="name ellipsis-2">{{goods.name}}</p>
            <p class="desc ellipsis">{{goods.desc}}</p>
            <p class="price">{{goods.price}}</p>
          </div>
          <div class="extra">
            <span>找相似</span>
            <span>发现现多宝贝 ></span>
          </div>
        </RouterLink>
      </swiper-slide>
      <div class="swiper-button-prev"><i class="iconfont icon-angle-left"></i></div>
      <div class="swiper-button-next"><i class="iconfont icon-angle-right"></i></div>
    </swiper>
    
  </div>
</template>

<style lang="scss" scoped>
// swiper组件样式不生效，需要到全局样式styles文件调整
.swiper-group{
  width: 100%;
  position: relative;
  .swiper-pagination{
    margin-top: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    .swiper-pagination-bullet{
      margin: 0 8px;
      width: 8px;
      height: 8px;
      background: none !important;
      border-radius: 500px;
      border: 1px solid #cecece;
      border-radius: 7px;
      transition: all 0.5s ease;
      opacity: 1;
      cursor: pointer;
    }
    .swiper-pagination-bullet-active{
      -webkit-box-shadow: 0 0 0 4px #dfcead;
      -moz-box-shadow: 0 0 0 4px #dfcead;
      box-shadow: 0 0 0 4px #dfcead;
      background: #a7936e !important;
      border-radius: 500px;
      border: none;
    }
  }
  .swiper-button-prev,
  .swiper-button-next{
    width: 30px;
    height: 30px;
    background-image: unset;
    background-color: rgba(0,0,0,.35);
    border-radius: 50%;
    border: none;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 5;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: all .4s;
  }
  .swiper-button-prev::after,
  .swiper-button-next::after{
    display: none;
  }
  .swiper-button-prev i,
  .swiper-button-next i{
    font-size: inherit;
    color: #fff;
  }
  .swiper-button-prev:hover,
  .swiper-button-next:hover{
    background-color: #d1aa87;
    color: #fff;
  }
  &:hover .swiper-button-prev,
  &:hover .swiper-button-next{
    opacity: 1;
  }
  .swiper-button-prev{
    left: 1%;
  }
  &:hover .swiper-button-prev{
    left: 3%;
  }
  .swiper-button-next{
    right: 1%;
  }
  &:hover .swiper-button-next{
    right: 3%;
  }
}
.goods-item{
  display: block;
  position: relative;
  overflow: hidden;
  border: 1px solid #ededed;
  transition: all .5s;
  .pic{
    width: 100%;
    height: 225px;
    img{
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }
  .info-desc{
    padding: 15px;
  }
  p{
    font-size: 14px;
  }
  p.name{
    height: 40px;
  }
  p.desc{
    font-size: 12px;
    color: #999;
    height: 17px;
    margin-top: 5px;
  }
  p.price{
    margin-top: 10px;
    font-size: 20px;
    color: $priceColor;
  }
  .extra{
    position: absolute;
    left: 0;
    bottom: 0;
    height: 86px;
    width: 100%;
    background: #27ba9b;
    text-align: center;
    transform: translate3d(0,100%,0);
    transition: all .5s;
    span{
      display: block;
      color: #fff;
      width: 120px;
      margin: 0 auto;
      line-height: 30px;
    }
    span:first-child{
      font-size: 18px;
      border-bottom: 1px solid #fff;
      line-height: 40px;
      margin-top: 5px;
    }
  }
  &:hover{
    border-color: $xtxColor;
  }
  &:hover .extra{
    transform: none;
  }
}
</style>
